package com.onetoall.yjt;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by user on 2016/12/2.
 */

public class UserDao {

    private  SQLiteDatabase db;

    public  UserDao(Context context){
        MyDataHelper helper = new MyDataHelper(context);
        db = helper.getWritableDatabase();
    }
    public long insertValue(String name,String number){
        ContentValues values = new ContentValues();
        values.put("name",name);
        values.put("number",number);
        return db.insert("users", null, values);
    }
    public List<UserBean> querryBean(){
        List<UserBean> temp = new ArrayList<>( );
        String sql = "select * from users";
        Cursor cursor = db.rawQuery(sql,null);
        while (cursor.moveToNext()){
            UserBean bean = new UserBean();
            bean.setNumber(cursor.getString(cursor.getColumnIndex("number")));
            bean.setName(cursor.getString(cursor.getColumnIndex("name")));
            temp.add(bean);
        }
        return temp;
    }
    public long updataData(String number,String string){
        ContentValues values = new ContentValues( );
        values.put("name",string);
       long t= db.update("users",values,"number=?",new String[]{number});
        return t;
    }
    public long deleteData(String number){
        long m = db.delete("users","number=?",new String[]{number});
        return m;
    }
}
